package com.iedu.demo.lgq.service.impl;

import com.iedu.demo.lgq.entity.TbUserFavorites;
import com.iedu.demo.lgq.mapper.UserFavoritesMapper;
import com.iedu.demo.lgq.service.UserFavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserFavoritesServiceImpl implements UserFavoritesService {

    @Autowired
    private UserFavoritesMapper favoritesMapper;

    @Override
    public void addToFavorites(String userName, String itemId) {
        TbUserFavorites favorites = new TbUserFavorites();
        favorites.setUserName(String.valueOf(userName));
        favorites.setItemId(String.valueOf(itemId));
        favorites.setCreateTime(new Date()); // 当前时间
        favoritesMapper.addToFavorites(favorites);
    }

    @Override
    public List<TbUserFavorites> findFavoritesByUserId(String userId) {
        return favoritesMapper.findFavoritesByUserId(userId);
    }

    @Override
    public void removeFromFavorites(String userId, String itemId) {
        favoritesMapper.removeFromFavorites(userId, itemId);
    }
}
